<%@ page language="java"
         import="com.ruohi.gift.order.OrderOperate,com.ruohi.gift.order.OrderStatus,com.ruohi.manage.DBType,com.ruohi.manage.PoolManager,com.ruohi.manage.Tools,com.ruohi.util.common.*,com.ruohi.util.dbutil.DBHelper,com.ruohi.webservice.WEBEmail"
         pageEncoding="UTF-8"%>
<%@page import="com.ruohi.weixin.HttpsUtil" %>
<%@page import="com.ruohi.weixin.WeiTools" %>
<%@page import="jxl.Workbook" %>
<%@page import="jxl.format.Alignment" %>
<%@page import="jxl.format.Border" %>
<%@page import="jxl.write.*" %>
<%@page import="org.apache.commons.httpclient.HttpClient"%>
<%@page import="org.apache.commons.httpclient.NameValuePair"%>
<%@page import="org.apache.commons.httpclient.methods.PostMethod" %>
<%@page import="org.apache.commons.httpclient.params.HttpMethodParams" %>
<%@page import="org.apache.commons.io.FileUtils" %>
<%@page import="org.apache.solr.client.solrj.impl.HttpSolrServer"%>
<%@page import="org.apache.solr.common.SolrInputDocument"%>
<%@page import="org.json.JSONArray" %>
<%@page import="org.json.JSONObject" %>
<%@page import="java.io.File" %>
<%@page import="java.io.OutputStream,java.net.URL" %>
<%@page import="java.sql.Connection" %>
<%@ page import="java.text.NumberFormat" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.*" %>
<%
	String flag = CommonString.getFormatPara(request.getParameter("flag"));
	String tableName = CommonString.getFormatPara(request.getParameter("tableName"));
	String table_prefix = Env.getInstance().getProperty("table_prefix");
	Connection connection = null;
	DBHelper dbHelper = DBHelper.getInstance();
	Map adminInfo = (Map) session.getAttribute("adminInfo");
	String rs = "fail";
	String enumNo = CommonString.getFormatPara(request.getParameter("enumNo"));
	try {
		connection = PoolManager.getConnection(DBType.getDBTypeByEnum(enumNo));
		//复制采集栏目
		if("copy".equals(flag)){
			String ids = CommonString.getFormatPara(request.getParameter("del_id"));
			if (null != ids && ids.length() > 0) {
				String []idstr = ids.split(",");
				for(int i = 0;idstr!= null && i<idstr.length;i++){
			String sql = " insert into index_data (add_user,add_date,add_ip,channel_uuid,title,url,sub_title,sub_url,img,pub_date,sort_flag,is_pub,order_no,uuid,cate) select add_user,add_date,add_ip,channel_uuid,title+'-复制',url,sub_title,sub_url,img,pub_date,sort_flag,is_pub,order_no+1,'"+UUID.randomUUID().toString()+"',cate from index_data where uuid = "+idstr[i]+" ";
				rs = dbHelper.execute(sql,connection)+"";
				}
			}
		}
		//频道树
		if ("channel_tree".equals(flag)) {
			String whereStr = CommonString.getFormatPara(request.getParameter("whereStr"));
			String orderByStr = CommonString.getFormatPara(request.getParameter("orderByStr"));
			//目前是全部
			String sql = " select * from " + tableName + " where 1 = 1 ";
			sql += whereStr;
			if (!"".equals(orderByStr)) {
				sql += " order by " + orderByStr;
			}
			List channels = dbHelper.getMapList(sql, connection);
			rs = Common.getTreeData(channels);
		}
		//微信自定义菜单
//		if ("weixin_menu".equals(flag)) {
//			String token = WeiTools.getToken(application);
//			String menuJson = Common.doGet("https://api.weixin.qq.com/cgi-bin/menu/get?access_token="+token);
//			System.out.println(menuJson);
//			JSONObject jo1 = new JSONObject(menuJson);
//			JSONObject jo2 = new JSONObject(jo1.getJSONObject("menu").toString());
//			JSONArray ja1 = new JSONArray(jo2.getJSONArray("button").toString());
//			List <Map>l = new ArrayList();
//			Map m = null;
//			for(int i = 0;i<ja1.length();i++){
//				m = new HashMap();
//				m.put("parent_no","0");
//				m.put("no","p"+i);
//				m.put("name",ja1.getJSONObject(i).get("name"));
//				l.add(m);
//				m = null;
//				JSONArray sja = new JSONArray(ja1.getJSONObject(i).get("sub_button").toString());
//				for(int j = 0;j<sja.length();j++){
//					if(sja.getJSONObject(j).has("name")){
//						m = new HashMap();
//						m.put("parent_no","p"+i);
//						m.put("no","s"+j);
//						m.put("name",sja.getJSONObject(j).get("name"));
//						m.put("url",sja.getJSONObject(j).get("url"));
//						l.add(m);
//						m = null;
//					}
//				}
//			}
//			rs = Common.getTreeNo(l);
//			//System.out.println(rs);
//		}
		//微信自定义菜单-new
		if ("weixin_menu".equals(flag)) {
			String whereStr = CommonString.getFormatPara(request.getParameter("whereStr"));
			String orderByStr = CommonString.getFormatPara(request.getParameter("orderByStr"));
			//目前是全部
			String sql = " select * from " + tableName + " where 1 = 1 ";
			sql += whereStr;
			if (!"".equals(orderByStr)) {
				sql += " order by " + orderByStr;
			} else {
				sql += " order by order_no desc , id asc ";
			}
			List channels = dbHelper.getMapList(sql, connection);
			rs = Common.getTreeNo(channels);
		}
		//更新微信自定义菜单
		if ("upWeixinMenu".equals(flag)) {
			//目前是全部
			String sql = " select * from weixin_menu where 1 = 1 and is_show=1 order by  order_no desc , id asc ";
			List<Map> menus = dbHelper.getMapList(sql, connection);
			String json = WeiTools.getMenuJson(menus,"0");
			String url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=";
			url += WeiTools.getToken(application);
			String result = new String(HttpsUtil.post(url,json,"utf-8"));
			JSONObject js = new JSONObject(result);
			rs = js.get("errcode").toString();
			//System.out.println("rs:"+rs);
			//System.out.println("result:"+result);
		}
		//更新微信自定义菜单
		if ("delWeixinMenu".equals(flag)) {
			//目前是全部
			String url = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=";
			url += WeiTools.getToken(application);
			rs = Common.doGet(url);
			System.out.println("rs:"+rs);
		}
		//频道树
		if ("eunm_tree".equals(flag)) {
			String whereStr = CommonString.getFormatPara(request.getParameter("whereStr"));
			String orderByStr = CommonString.getFormatPara(request.getParameter("orderByStr"));
			//目前是全部
			String sql = " select * from " + tableName + " where 1 = 1 ";
			sql += whereStr;
			if (!"".equals(orderByStr)) {
				sql += " order by " + orderByStr;
			} else {
				sql += " order by order_no desc , id asc ";
			}
			List channels = dbHelper.getMapList(sql, connection);
			rs = Common.getTreeNo(channels);
		}
		//获得编号
		if ("get_no".equals(flag)) {
			//rs = Common.getNo(CommonString.getFormatPara(request.getParameter("pno")),tableName);
			rs = Tools.getNo(CommonString.getFormatPara(request.getParameter("pno")), tableName, enumNo);
		}
		//获得键枚举
		if ("get_enum".equals(flag)) {
			Map enumMap = (Map) application.getAttribute("enumMap");
			JSONObject jsonObject = new JSONObject(enumMap);
			rs = CommonString.getFormatPara(request.getParameter("callback")) + "(" + jsonObject.toString() + ")";
		}
		//根据键及application名称获得application中的值名称
		if ("get_name".equals(flag)) {
			String appName = CommonString.getFormatPara(request.getParameter("appName"));
			Map map = (Map) application.getAttribute(appName);
			JSONObject jsonObject = new JSONObject(map);
			rs = CommonString.getFormatPara(request.getParameter("callback")) + "(" + jsonObject.toString() + ")";
		}
		//根据键及application名称获得application中的值名称
		if("".equals(flag)){
			
		}
		//获得文件的内容
		if ("get_file_html".equals(flag)) {
			String absolutePath = Common.getAbsolutePath(request);
			String fileName = CommonString.getFormatPara(request.getParameter("fileName"));
			File f = new File(absolutePath + "/template/" + fileName);
			rs = FileUtils.readFileToString(f, "utf-8");
		}
		//获取表的字段
		if ("get_field_by_table".equals(flag)) {
			String sql = " select a.name from syscolumns a,systypes b,sysobjects c ";
			sql += " where a.xtype=b.xtype and a.id=c.id and c.name= '" + tableName + "' ";
			sql += " and b.name <> 'sysname' ";
			sql += " order by a.id ";
			List columns = dbHelper.getMapList(sql, connection);
			Map m = null;
			for (int i = 0; i < columns.size(); i++) {
				m = (Map) columns.get(i);
				out.print(m.get("name"));
				if (i != (columns.size() - 1)) {
					out.print("&nbsp;,&nbsp;");
				}
			}
		}
		//更新浏览次数并返回浏览次数
		if ("upd_view_count".equals(flag)) {
			String uuid = CommonString.getFormatPara(request.getParameter("id"));
			dbHelper.execute(" update " + tableName + " set view_count = isnull(view_count,0)+1 where uuid = ? ", new Object[] { uuid }, connection);
			Integer times = (Integer) dbHelper.getOne(" select view_count from " + tableName + " where uuid = ? ", new Object[] { uuid }, connection);
			rs = "" + times;
		}
		//获取图形验证码
		if ("rand".equals(flag)) {
			Common.getAuthImg(request, response);
			out.clear();
			out = pageContext.pushBody();
			return;
		}
		//获取验证码(字符串格式)
		if ("getRandNum".equals(flag)) {
			rs = (String) session.getAttribute("rand");
		}
		//全站生成
		if ("allHtmlCreate".equals(flag)) {
			Integer second = 0;
			long d1 = Calendar.getInstance().getTime().getTime();
			List<Map> channels = dbHelper.getMapList(" select id from " + table_prefix + "common_channel ", connection);
			Map params = null;
			for (Map m : channels) {
				params = new HashMap();
				params.put("eventAfter", "channelTemplate");
				params.put("keyId", m.get("id"));
				Common.doPost(Common.getDomain(request) + "/backend/action/after_own.jsp", params, request.getCookies());
			}
			long d2 = Calendar.getInstance().getTime().getTime();
			long l = d2 - d1;
			long day = l / (24 * 60 * 60 * 1000);
			long hour = (l / (60 * 60 * 1000) - day * 24);
			long min = ((l / (60 * 1000)) - day * 24 * 60 - hour * 60);
			long s = (l / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
			rs = "生成成功<br />共计用时" + s + "秒";
		}
		//商家从车源车辆总数
		if ("getDealerCount".equals(flag)) {

		}
		//获取个人工作类型
		if ("getAddWorkCategory".equals(flag)) {
			List<Map> maps = dbHelper
					.getMapList(" select uuid,name from service_work_category where user_uuid = ? order by order_no desc ", new Object[] { adminInfo.get("uuid") }, connection);
			List<Map> rsMaps = new ArrayList<Map>(0);
			if (null != maps && maps.size() > 0) {
				Map rsMap = null;
				List<Map> tList = null;
				for (Map m : maps) {
					rsMap = new HashMap();
					rsMap.put("uuid", m.get("uuid"));
					rsMap.put("name", m.get("name"));
					tList = dbHelper.getMapList(" select * from service_work where category_uuid = ? ", new Object[] { m.get("uuid") }, connection);
					if (null != tList) {
						rsMap.put("list", tList);
					} else {
						rsMap.put("list", new ArrayList<Map>(0));
					}
					rsMaps.add(rsMap);
				}
				rs = new JSONArray(rsMaps).toString();
			} else {
				rs = "[]";
			}
		}
		if ("get_brand".equals(flag)) {
			List<Map> brands = dbHelper.getMapList(" select * from used_brand order by letter ", connection);
			Map brandMap = new TreeMap();
			for (Map m : brands) {
				brandMap.put(m.get("id"), m.get("name"));
			}
			JSONObject jsonObject = new JSONObject(brandMap);
			rs = CommonString.getFormatPara(request.getParameter("callback")) + "(" + jsonObject.toString() + ")";
		}
		if ("get_category".equals(flag)) {
			List<Map> categorys = dbHelper.getMapList(" select * from used_catalog ", connection);
			Map categoryMap = new TreeMap();
			for (Map m : categorys) {
				categoryMap.put(m.get("id"), m.get("name"));
			}
			JSONObject jsonObject = new JSONObject(categoryMap);
			rs = CommonString.getFormatPara(request.getParameter("callback")) + "(" + jsonObject.toString() + ")";
		}
		//供应商管理-企业关键词-搜索点击量
		if ("getSearchCount".equals(flag)) {
			String num = "0";
			String keyword = CommonString.getFormatPara(request.getParameter("keyword"));
			String sql = "select top 1 clicked from supply_ad_click where kwd = '" + keyword + "'";
			Map m = dbHelper.getMap(sql, connection);
			if (m != null) {
				num = m.get("clicked").toString();
			}
			rs = num;
		}
		//会员详细页面，获得发布信息量
		if ("getInfoCount".equals(flag)) {
			String num = "0";
			String mno = CommonString.getFormatPara(request.getParameter("mno"));
			enumNo = CommonString.getFormatPara(request.getParameter("enumNo")) ;
			String id = CommonString.getFormatPara(request.getParameter("id")) ;
			String sql = "select count(*) as count from " + tableName + " where mem_no = '" + mno + "'";
			if("marketId_buy".equals(id)){
				sql += " and business_flag=11" ;
			}
			Map m = dbHelper.getMap(sql, connection);
			if (m != null) {
				num = m.get("count").toString();
			}
			rs = num;
		}
		//会员列表页面，获得发布信息量
		if ("showCount".equals(flag)) {
			String num = "0";
			String mno = CommonString.getFormatPara(request.getParameter("mno"));
			String sql = "";
			//供求
			DBHelper.freeConnection(connection);
			Connection connection_106008 = null;
			Connection connection_106003 = null;
			Connection connection_106002 = null;
			Connection connection_106006 = null;
			try{
				connection_106008 = PoolManager.getConnection(DBType.getDBTypeByEnum("106008"));
				tableName = "sell_buy_market";
				sql = "select count(*) as count from " + tableName + " where mem_no = '" + mno + "'";
				Map m = dbHelper.getMap(sql, connection_106008);
				if (m != null) {
					num = m.get("count").toString();
				}
				//租赁
				if (num != null && num.equals("0")) {
					connection_106003 = PoolManager.getConnection(DBType.getDBTypeByEnum("106003"));
					tableName = "rent_info";
					sql = "select count(*) as count from " + tableName + " where mem_no = '" + mno + "'";
					m = dbHelper.getMap(sql, connection_106003);
					if (m != null) {
						num = m.get("count").toString();
					}
				}
				
				//二手供应
				if (num != null && num.equals("0")) {
					connection_106002 = PoolManager.getConnection(DBType.getDBTypeByEnum("106002"));
					tableName = "used_sell";
					sql = "select count(*) as count from " + tableName + " where mem_no = '" + mno + "'";
					m = dbHelper.getMap(sql, connection_106002);
					if (m != null) {
						num = m.get("count").toString();
					}
				}
				//配件供应
				if (num != null && num.equals("0")) {
					connection_106006 = PoolManager.getConnection(DBType.getDBTypeByEnum("106006"));
					tableName = "supply";
					sql = "select count(*) as count from " + tableName + " where mem_no = '" + mno + "'";
					m = dbHelper.getMap(sql, connection_106006);
					if (m != null) {
						num = m.get("count").toString();
					}
				}
				//二手求购
				if (num != null && num.equals("0")) {
					tableName = "used_buy";
					sql = "select count(*) as count from " + tableName + " where mem_no = '" + mno + "'";
					m = dbHelper.getMap(sql, connection_106002);
					if (m != null) {
						num = m.get("count").toString();
					}
				}
				//配件求购
				if (num != null && num.equals("0")) {
					tableName = "buy";
					sql = "select count(*) as count from " + tableName + " where mem_no = '" + mno + "'";
					m = dbHelper.getMap(sql, connection_106006);
					if (m != null) {
						num = m.get("count").toString();
					}
				}
				rs = num;
			}catch(Exception e){
				
			}finally{
				DBHelper.freeConnection(connection_106008);
				DBHelper.freeConnection(connection_106003);
				DBHelper.freeConnection(connection_106002);
				DBHelper.freeConnection(connection_106006);
			}
		}
		//获得会员类别名称
		if ("getMemFlagName".equals(flag)) {
			String memFlagName = "";
			String memFlag = CommonString.getFormatPara(request.getParameter("memFlag"));
			memFlagName = CommonString.getFormatPara(CommonApplication.getEnumChildren("100", application).get(memFlag));
			rs = memFlagName;
		}
		//根据sql语句生成UI表格
		if ("sqlToGrid".equals(flag)) {
			String sql = CommonString.getFormatPara(request.getParameter("sql"));
			List<Map> list = dbHelper.getMapList(sql, connection);
			JSONObject obj = new JSONObject();
			if (null != list && list.size() > 0) {
				obj.put("Rows", new JSONArray(list));
				obj.put("Total", list.size());
			} else {
				obj.put("Rows", new JSONArray());
				obj.put("Total", 0);
			}
			rs = obj.toString();
		}

		/************************商品网部分开始*************************/
		//检测用户唯一
		if ("checkUserUnique".equals(flag)) {
			String mem_no = CommonString.getFormatPara(request.getParameter("mem_no"));
			String query = "select id from gift_member where mem_no='" + mem_no + "'";
			Map userMap = dbHelper.getMap(query, connection);
			if (userMap == null) {
				rs = "0"; //可以注册
			} else {
				rs = "1"; //不能注册
			}
		}
		
		//检测合伙人专属链接唯一
		if ("checkPartnerUrlUnique".equals(flag)) {
			String own_url = CommonString.getFormatPara(request.getParameter("own_url"));
			String mem_no = CommonString.getFormatPara(request.getParameter("mem_no"));
			String query = "select id from gift_member where own_url='" + own_url + "' and mem_no!='"+mem_no+"'";
			Map userMap = dbHelper.getMap(query, connection);
			if (userMap == null) {
				rs = "0"; //可以注册
			} else {
				rs = "1"; //不能注册
			}
		}

		//后台订单列表页显示订单可用的操作
		if (flag.equals("gift_show_order_operate")) {
			String order_num = CommonString.getFormatPara(request.getParameter("order_num"));
			String order_operate = CommonString.getFormatPara(request.getParameter("order_operate"));
			rs = OrderOperate.showOrderEnableOperate(order_num, order_operate, "Back");
		}

		//取消订单
		if (flag.equals("gift_cancelorder")) {
			String order_num = CommonString.getFormatPara(request.getParameter("order_num"));
			dbHelper.execute("update gift_order set order_status=0 where order_num='" + order_num + "'", connection);
			
			//取消订单后，退回使用商品卡支付的金额
			Map orderMap = dbHelper.getMap("select card_no,card_total_price from gift_order where order_num='" + order_num + "'", connection);
			if(orderMap != null){
				String card_no = CommonString.getFormatPara(orderMap.get("card_no"));
				double card_total_price = CommonString.getFormatDouble(orderMap.get("card_total_price"));
				if(!card_no.equals("") && card_total_price > 0){
					dbHelper.execute("insert into gift_card_pay_history (add_user,add_date,add_ip,uuid,card_no,pay_money) values (?,?,?,?,?,?)", new Object[]{ CommonString.getFormatPara(adminInfo.get("usern")),CommonDate.getToday("yyyy-MM-dd HH:mm:ss"),Common.getIp(request),UUID.randomUUID().toString(),card_no,-card_total_price }, connection);
				}
			}
			
			//写入操作记录表
			String historySql = "insert into gift_order_operate_history (add_user,add_date,add_ip,uuid,order_num,mem_no,order_status,last_modify_user,last_modify_date,last_modify_ip) values (?,?,?,?,?,?,?,?,?,?)";
			String add_user = CommonString.getFormatPara(adminInfo.get("usern"));
			String add_date = CommonDate.getToday("yyyy-MM-dd HH:mm:ss");
			String add_ip = Common.getIp(request);
			String uuid = UUID.randomUUID().toString();
			String mem_no = CommonString.getFormatPara(adminInfo.get("usern"));
			int order_status = OrderStatus.CANCELED;
			String last_modify_user = add_user;
			String last_modify_date = add_date;
			String last_modify_ip = add_ip;
			Object[] paras = { add_user,add_date,add_ip,uuid,order_num,mem_no,order_status,last_modify_user,last_modify_date,last_modify_ip };
			dbHelper.execute(historySql,paras,connection);
			
			rs = "1";
		}
		
		//订单退款
		if (flag.equals("gift_refundorder")) {
			String order_num = CommonString.getFormatPara(request.getParameter("order_num"));
			dbHelper.execute("update gift_order set order_status=6 where order_num='" + order_num + "'", connection);
			
			//取消订单后，退回使用商品卡支付的金额
			Map orderMap = dbHelper.getMap("select card_no,card_total_price from gift_order where order_num='" + order_num + "'", connection);
			if(orderMap != null){
				String card_no = CommonString.getFormatPara(orderMap.get("card_no"));
				double card_total_price = CommonString.getFormatDouble(orderMap.get("card_total_price"));
				if(!card_no.equals("") && card_total_price > 0){
					dbHelper.execute("insert into gift_card_pay_history (add_user,add_date,add_ip,uuid,card_no,pay_money) values (?,?,?,?,?,?)", new Object[]{ CommonString.getFormatPara(adminInfo.get("usern")),CommonDate.getToday("yyyy-MM-dd HH:mm:ss"),Common.getIp(request),UUID.randomUUID().toString(),card_no,-card_total_price }, connection);
				}
			}
			
			//写入操作记录表
			String historySql = "insert into gift_order_operate_history (add_user,add_date,add_ip,uuid,order_num,mem_no,order_status,last_modify_user,last_modify_date,last_modify_ip) values (?,?,?,?,?,?,?,?,?,?)";
			String add_user = CommonString.getFormatPara(adminInfo.get("usern"));
			String add_date = CommonDate.getToday("yyyy-MM-dd HH:mm:ss");
			String add_ip = Common.getIp(request);
			String uuid = UUID.randomUUID().toString();
			String mem_no = CommonString.getFormatPara(adminInfo.get("usern"));
			int order_status = OrderStatus.REFUND;
			String last_modify_user = add_user;
			String last_modify_date = add_date;
			String last_modify_ip = add_ip;
			Object[] paras = { add_user,add_date,add_ip,uuid,order_num,mem_no,order_status,last_modify_user,last_modify_date,last_modify_ip };
			dbHelper.execute(historySql,paras,connection);
			
			rs = "1";
		}
		
		//配货
		if (flag.equals("gift_assortorder")) {
			String order_num = CommonString.getFormatPara(request.getParameter("order_num"));
			dbHelper.execute("update gift_order set order_status=3 where order_num='" + order_num + "'", connection);
			
			//写入操作记录表
			String historySql = "insert into gift_order_operate_history (add_user,add_date,add_ip,uuid,order_num,mem_no,order_status,last_modify_user,last_modify_date,last_modify_ip) values (?,?,?,?,?,?,?,?,?,?)";
			String add_user = CommonString.getFormatPara(adminInfo.get("usern"));
			String add_date = CommonDate.getToday("yyyy-MM-dd HH:mm:ss");
			String add_ip = Common.getIp(request);
			String uuid = UUID.randomUUID().toString();
			String mem_no = CommonString.getFormatPara(adminInfo.get("usern"));
			int order_status = OrderStatus.ASSORTING;
			String last_modify_user = add_user;
			String last_modify_date = add_date;
			String last_modify_ip = add_ip;
			Object[] paras = { add_user,add_date,add_ip,uuid,order_num,mem_no,order_status,last_modify_user,last_modify_date,last_modify_ip };
			dbHelper.execute(historySql,paras,connection);
			
			rs = "1";
		}
		//发货短信提醒
		if(flag.equals("gift_shipsmsalert")){
			String order_num = CommonString.getFormatPara(request.getParameter("order_num"));
			//String sms_phone = CommonString.getFormatPara(request.getParameter("sms_phone"));
			//String sms_content = CommonString.getFormatPara(request.getParameter("sms_content"));
			String ordQuery = "select receive_name,receive_phone from gift_order where order_num='"+ order_num +"'";
			Map ordMap = dbHelper.getMap(ordQuery, connection);
			if(ordMap != null){
				String sms_phone = CommonString.getFormatPara(ordMap.get("receive_phone"));
				String sms_content = "亲爱的" + CommonString.getFormatPara(ordMap.get("receive_name")) + "，您在太阳商城购买的订单号为" + order_num + "的商品已发货，请注意查收，谢谢！【太阳商城】";
				HttpClient client = new HttpClient();
				client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "utf-8");
				PostMethod method = new PostMethod("http://service.saygou.com/http/utils/sms.jsp");
				NameValuePair mobile = new NameValuePair("phone", sms_phone);
				NameValuePair content = new NameValuePair("content", sms_content);
				NameValuePair source = new NameValuePair("source", "195008");
				method.setRequestBody(new NameValuePair[] {  mobile, content, source });
				String res = "0";
				try {
					client.executeMethod(method);
					res = method.getResponseBodyAsString().trim();
				} catch (Exception e) {
					e.printStackTrace();
				} finally {
					method.releaseConnection();
				}
				//String resLog = "未知";
				if(res.equals("-1")){
					rs="-1"; //resLog = "手机号或者内容为空";
				}else if(res.equals("-2")){
					rs="-2"; //resLog = "手机号位数不正确";
				}else if(res.equals("-3")){
					rs="-3"; //resLog = "发送内容超过最大长度";
				}else if(res.equals("-4")){
					rs="-4"; //resLog = "短信接口异常";
				}else if(res.equals("-5")){
					rs="-5"; //resLog = "手机号码过多";
				}else if(res.equals("1")){
					rs="1"; //resLog = "成功";
				}else if(res.equals("0")){
					rs="0"; //resLog = "失败";
				}
			}else{
				rs = "0";
			}
			
			if(rs.equals("1")){
				dbHelper.execute("update gift_order set sms_alert_send=1 where order_num='" + order_num + "'", connection); //更新短信提示状态为已发送
			}else{
				dbHelper.execute("update gift_order set sms_alert_send=-1 where order_num='" + order_num + "'", connection); //更新短信提示状态为发送失败
			}
		}
		//完成
		if (flag.equals("gift_finishorder")) {
			String order_num = CommonString.getFormatPara(request.getParameter("order_num"));
			dbHelper.execute("update gift_order set order_status=5,confirmrecive_date='"+CommonDate.getToday("yyyy-MM-dd HH:mm:ss")+"' where order_num='" + order_num + "'", connection);
			
			//写入操作记录表
			String historySql = "insert into gift_order_operate_history (add_user,add_date,add_ip,uuid,order_num,mem_no,order_status,last_modify_user,last_modify_date,last_modify_ip) values (?,?,?,?,?,?,?,?,?,?)";
			String add_user = CommonString.getFormatPara(adminInfo.get("usern"));
			String add_date = CommonDate.getToday("yyyy-MM-dd HH:mm:ss");
			String add_ip = Common.getIp(request);
			String uuid = UUID.randomUUID().toString();
			String mem_no = CommonString.getFormatPara(adminInfo.get("usern"));
			int order_status = OrderStatus.FINISHED;
			String last_modify_user = add_user;
			String last_modify_date = add_date;
			String last_modify_ip = add_ip;
			Object[] paras = { add_user,add_date,add_ip,uuid,order_num,mem_no,order_status,last_modify_user,last_modify_date,last_modify_ip };
			dbHelper.execute(historySql,paras,connection);
			
			rs = "1";
		}
		//发货
		if (flag.equals("gift_shiporder")) {
			//TODO: 发货的处理
			String order_num = CommonString.getFormatPara(request.getParameter("order_num"));
			dbHelper.execute("update gift_order set order_status=" + OrderStatus.SHIPPED + " where order_num='" + order_num + "'", connection);
			
			//写入操作记录表
			String historySql = "insert into gift_order_operate_history (add_user,add_date,add_ip,uuid,order_num,mem_no,order_status,last_modify_user,last_modify_date,last_modify_ip) values (?,?,?,?,?,?,?,?,?,?)";
			String add_user = CommonString.getFormatPara(adminInfo.get("usern"));
			String add_date = CommonDate.getToday("yyyy-MM-dd HH:mm:ss");
			String add_ip = Common.getIp(request);
			String uuid = UUID.randomUUID().toString();
			String mem_no = CommonString.getFormatPara(adminInfo.get("usern"));
			int order_status = OrderStatus.SHIPPED;
			String last_modify_user = add_user;
			String last_modify_date = add_date;
			String last_modify_ip = add_ip;
			Object[] paras = { add_user,add_date,add_ip,uuid,order_num,mem_no,order_status,last_modify_user,last_modify_date,last_modify_ip };
			dbHelper.execute(historySql,paras,connection);
			
			rs="1";
		}
		
		//根据订单号获得订单UUID
		if(flag.equals("getOrderUUID")){
			String order_num = CommonString.getFormatPara(request.getParameter("order_num"));
			Map orderMap = dbHelper.getMap("select uuid from gift_order where order_num='" + order_num + "'", connection);
			if(orderMap!=null){
				String uuid = CommonString.getFormatPara(orderMap.get("uuid"));
				rs = uuid;
			}else{
				rs = "";
			}
		}

		//后台显示订单提示
		if (flag.equals("gift_show_order_tips")) {
			String order_num = CommonString.getFormatPara(request.getParameter("order_num"));
			String mem_no = CommonString.getFormatPara(request.getParameter("mem_no"));
			int order_status = CommonString.getFormatInt(request.getParameter("order_status"));
			rs = OrderOperate.showOrderTips(order_num, mem_no, order_status, "Back");
		}
		//退款
		if(flag.equals("refund")){
			Common.doPostHttpAsync("", request.getParameterMap());
		}
		//退款提醒邮件（发给财务的）
		if(flag.equals("refundAlertEmail")){
			double refund_price = CommonString.getFormatDouble(request.getParameter("refund_price"));
			String order_num = CommonString.getFormatPara(request.getParameter("order_num"));
			Map orderMap = dbHelper.getMap("select alipay_trade_no from gift_order where order_num=?", new Object[]{ order_num }, connection);
			if(orderMap!=null && !CommonString.getFormatPara(orderMap.get("alipay_trade_no")).equals("")){
				String content = "太阳商城用户的退款申请已经审批通过，支付宝交易号为" + CommonString.getFormatPara(orderMap.get("alipay_trade_no")) + "，退款金额为￥"+refund_price+"，请及时处理。<a target=\"_blank\" href=\"https://www.alipay.com/\">立即进入支付宝</a>";
				//WEBEmail.sendMail("songch@21-sun.com,chenyan@21-sun.com", "tansl@21-sun.com,zouhc@21-sun.com,liuyang@21-sun.com,wangjj@21-sun.com,wanggq@21-sun.com,zhengfeng@21-sun.com,mengl@21-sun.com", "太阳商城退款提醒", content);
			}
			
			rs = "1";
		}
		
		//生成商品lucene索引
		if(flag.equals("generateProductIndex")){
			Map brandMap = (Map)application.getAttribute("giftBrandMap");
			Map categoryMap = (Map)application.getAttribute("giftCategoryMap");
			String product_no = CommonString.getFormatPara(request.getParameter("no"));
			String productQuery = "select id,uuid,no,short_no,name,category,brand,price,price_promotion,price_agent,price_staff,img,param,param_key,pub_date,isnull(view_count, 0) as view_count,order_no,intro,is_show,isnull(is_cus,0) as is_cus,min_buy_count from gift_product where no=?";
			Map productMap = dbHelper.getMap(productQuery, new Object[]{ product_no }, connection);
			String httpUrl = Env.getInstance().getProperty("solr_service_url")+"sun21_gift";
			HttpSolrServer server = new HttpSolrServer(httpUrl);
			server.deleteByQuery("no:" + product_no); //删除原有索引
			if(productMap!=null){ //如果数据不为空，重新创建索引
				SolrInputDocument doc = new SolrInputDocument();
				doc.addField("id",CommonString.getFormatPara(productMap.get("id")));
				doc.addField("uuid", CommonString.getFormatPara(productMap.get("uuid")));
				doc.addField("no", CommonString.getFormatPara(productMap.get("no")));
				doc.addField("name",CommonString.getFormatPara(productMap.get("name")).toUpperCase());
				doc.addField("name_pinyin", CnToFullSpell.getFullSpell(CommonString.getFormatPara(productMap.get("name"))));
				doc.addField("category", CommonString.getFormatPara(productMap.get("category")));
				doc.addField("brand", CommonString.getFormatPara(productMap.get("brand")));
				doc.addField("price", CommonString.getFormatDouble(productMap.get("price")));
				doc.addField("price_promotion", CommonString.getFormatDouble(productMap.get("price_promotion")));
				doc.addField("price_agent", CommonString.getFormatDouble(productMap.get("price_agent")));
				doc.addField("price_staff", CommonString.getFormatDouble(productMap.get("price_staff")));
				doc.addField("img", CommonString.getFormatPara(productMap.get("img")));
				doc.addField("param", CommonString.getFormatPara(productMap.get("param")));
				doc.addField("param_key", CommonString.getFormatPara(productMap.get("param_key")));
				doc.addField("pub_date", CommonDate.getFormatDate("yyyy-MM-dd HH:mm:ss", productMap.get("pub_date")));
				doc.addField("view_count", CommonString.getFormatInt(productMap.get("view_count")));
				doc.addField("order_no", CommonString.getFormatInt(productMap.get("order_no")));
				doc.addField("intro", CommonString.getFormatPara(productMap.get("intro")));
				doc.addField("is_show", CommonString.getFormatInt(productMap.get("is_show")));
				doc.addField("is_cus", CommonString.getFormatInt(productMap.get("is_cus")));
				doc.addField("min_buy_count", CommonString.getFormatInt(productMap.get("min_buy_count")));
				String category_no = CommonString.getFormatPara(productMap.get("category"));
				int category_level = category_no.length() / 3;
				String cateegoryNameStr = "";
				for(int i=1; i<=category_level; i++){
					cateegoryNameStr += CommonString.getFormatPara(categoryMap.get(category_no.substring(0, i*3)));
				}
				doc.addField("search_field", CommonString.getFormatPara(productMap.get("short_no")) + CommonString.getFormatPara(productMap.get("no")) + CommonString.getFormatPara(productMap.get("name")) + CommonString.getFormatPara(brandMap.get(productMap.get("brand"))) + cateegoryNameStr);
				server.add(doc);
			}
			server.commit();
			rs = "1";
		}
		//生成全部商品的lucene索引
		if(flag.equals("generateAllProductIndex")){
			Map brandMap = (Map)application.getAttribute("giftBrandMap");
			Map categoryMap = (Map)application.getAttribute("giftCategoryMap");
			String productQuery = "select id,uuid,no,short_no,name,category,brand,price,price_promotion,price_agent,price_staff,img,param,param_key,pub_date,isnull(view_count, 0) as view_count,order_no,intro,is_show,isnull(is_cus,0) as is_cus,min_buy_count from gift_product";
			List<Map> productList = dbHelper.getMapList(productQuery, connection);
			if(productList!=null && productList.size()>0){
				String httpUrl = Env.getInstance().getProperty("solr_service_url")+"sun21_gift";
				HttpSolrServer server = new HttpSolrServer(httpUrl);
				server.deleteByQuery("*:*");
				SolrInputDocument doc = null;
				List<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();
				for(Map product : productList){
					doc = new SolrInputDocument();
					doc.addField("id",CommonString.getFormatPara(product.get("id")));
					doc.addField("uuid", CommonString.getFormatPara(product.get("uuid")));
					doc.addField("no", CommonString.getFormatPara(product.get("no")));
					doc.addField("name",CommonString.getFormatPara(product.get("name")));
					doc.addField("name_pinyin", CnToFullSpell.getFullSpell(CommonString.getFormatPara(product.get("name"))));
					doc.addField("category", CommonString.getFormatPara(product.get("category")));
					doc.addField("brand", CommonString.getFormatPara(product.get("brand")));
					doc.addField("price", CommonString.getFormatDouble(product.get("price")));
					doc.addField("price_promotion", CommonString.getFormatDouble(product.get("price_promotion")));
					doc.addField("price_agent", CommonString.getFormatDouble(product.get("price_agent")));
					doc.addField("price_staff", CommonString.getFormatDouble(product.get("price_staff")));
					doc.addField("img", CommonString.getFormatPara(product.get("img")));
					doc.addField("param", CommonString.getFormatPara(product.get("param")));
					doc.addField("param_key", CommonString.getFormatPara(product.get("param_key")));
					doc.addField("pub_date", CommonDate.getFormatDate("yyyy-MM-dd", product.get("pub_date")));
					doc.addField("view_count", CommonString.getFormatInt(product.get("view_count")));
					doc.addField("order_no", CommonString.getFormatInt(product.get("order_no")));
					doc.addField("intro", CommonString.getFormatPara(product.get("intro")));
					doc.addField("is_show", CommonString.getFormatInt(product.get("is_show")));
					doc.addField("is_cus", CommonString.getFormatInt(product.get("is_cus")));
					doc.addField("min_buy_count", CommonString.getFormatInt(product.get("min_buy_count")));
					String category_no = CommonString.getFormatPara(product.get("category"));
					int category_level = category_no.length() / 3;
					String cateegoryNameStr = "";
					for(int i=1; i<=category_level; i++){
						cateegoryNameStr += CommonString.getFormatPara(categoryMap.get(category_no.substring(0, i*3)));
					}
					doc.addField("search_field", CommonString.getFormatPara(product.get("short_no")) + CommonString.getFormatPara(product.get("no")) + CommonString.getFormatPara(product.get("name")) + CommonString.getFormatPara(brandMap.get(product.get("brand"))) + cateegoryNameStr);
					docs.add(doc);
				}
				server.add(docs); 
				server.commit();
			}
			
			rs = "1";
		}
		//生成首页大类中的商品
		if(flag.equals("generationIndexRec")){
			String category = CommonString.getFormatPara(request.getParameter("category"));
            Common.doPostHttpAsync ( "http://www.52sdskj.com/tools/create/index_rec_product.jsp?category=" + category, null );
			rs = "1";
		}
		
		//获得产品中心指定品牌的产品
		if(flag.equals("getProProduct")){
			String pro_brand = CommonString.getFormatPara(request.getParameter("pro_brand"));
			String proProductQuery = "select id,name from pro_products where is_show=1 and factoryname='" + pro_brand + "' order by order_no";
			List<Map> productList = dbHelper.getMapList(proProductQuery, connection);
			JSONArray ary = new JSONArray(productList);
			rs = ary.toString();
		}
		//发送秒杀提醒邮件
		if(flag.equals("sendMiaoshaAlert")){
			String memberQuery = "select email from gift_member where state=1 and email is not null and email<>''";
			List<Map> emailList = dbHelper.getMapList(memberQuery, connection);
			if(emailList!=null && emailList.size()>0){
				String d_str = "";
				SimpleDateFormat simFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
				Calendar c = Calendar.getInstance();
				Date d_1030 = simFormat.parse(c.get(Calendar.YEAR) + "-" + (c.get(Calendar.MONTH) + 1) + "-" + c.get(Calendar.DAY_OF_MONTH) + " 10:30");
				Date d_1530 = simFormat.parse(c.get(Calendar.YEAR) + "-" + (c.get(Calendar.MONTH) + 1) + "-" + c.get(Calendar.DAY_OF_MONTH) + " 15:30");
				if(new Date().before(d_1030)){
					d_str = "10:30";
				}else if(new Date().after(d_1030) && new Date().before(d_1530)){
					d_str = "15:30";
				}
				String content = "尊贵的太阳商城会员：<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;您好，本期太阳商城【宝马一元秒杀】今日" + d_str + "准时开始，商品有限抢完为止。我们在此等您。<a href=\"http://t.cn/zQvbjIF\" target=\"_blank\">http://t.cn/zQvbjIF</a>";
				for(Map email:emailList){
					try{
						WEBEmail.sendMail(CommonString.getFormatPara(email.get("email")), "", "太阳商城秒杀活动提醒", content);
					}catch(Exception e){
						e.printStackTrace();
					}
				}
			}
		}
		//发送团购提醒邮件
		if(flag.equals("sendTuanAlert")){
			String begin_time = CommonString.getFormatPara(request.getParameter("begin_time"));
			begin_time = begin_time.substring(0, begin_time.length()-2);
			String memberQuery = "select email from gift_member where state=1 and email is not null and email<>''";
			List<Map> emailList = dbHelper.getMapList(memberQuery, connection);
			if(emailList!=null && emailList.size()>0){
				String content = "<H2 style=\"PADDING-BOTTOM: 0px; WIDOWS: 2; TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255,255); TEXT-INDENT: 0px; MARGIN: 0px; PADDING-LEFT: 0px; LETTER-SPACING: normal; PADDING-RIGHT: 0px; FONT: 700 20px/30px 微软雅黑; WHITE-SPACE: normal; ORPHANS: 2; COLOR: rgb(0,0,0); WORD-SPACING: 0px; PADDING-TOP: 60px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px\">";
                content += "<A style=\"PADDING-BOTTOM: 0px; MARGIN: 0px; OUTLINE-STYLE: none; OUTLINE-COLOR: invert; PADDING-LEFT: 0px; OUTLINE-WIDTH: medium; PADDING-RIGHT: 0px; COLOR: rgb(213,11,23); TEXT-DECORATION: none; PADDING-TOP: 0px\" href=\"http://www.52sdskj.com/tuan/\" target=_blank>太阳商城低价聚人气，疯狂预售团，震撼来袭，</A><a href=\"http://www.52sdskj.com/tuan/\">http://www.52sdskj.com/tuan/</a>&nbsp;机会不容错过。</H2>";
					  content += "<H2 style=\"PADDING-BOTTOM: 0px; WIDOWS: 2; TEXT-TRANSFORM: none; BACKGROUND-COLOR: rgb(255,255,255); TEXT-INDENT: 0px; MARGIN: 0px; PADDING-LEFT: 0px; LETTER-SPACING: normal; PADDING-RIGHT: 0px; FONT: 700 20px/30px 微软雅黑; WHITE-SPACE: normal; ORPHANS: 2; COLOR: rgb(0,0,0); WORD-SPACING: 0px; PADDING-TOP: 60px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px\">您想不到的超低价格。</H2>";
				for(Map email:emailList){
					try{
						WEBEmail.sendMail(CommonString.getFormatPara(email.get("email")), "", "太阳商城团购活动提醒", content);
					}catch(Exception e){
						e.printStackTrace();
					}
				}
			}
		}
		//生成首页banner
		if(flag.equals("generationIndexBanner")){
            Common.doPostHttpAsync ( "http://www.52sdskj.com/tools/create/index_banner.jsp", null );
			rs = "1";
		}
		//更新预订单处理状态
		if(flag.equals("updateAdvancedStatus")){
			String uuid = CommonString.getFormatPara(request.getParameter("uuid"));
			int status = CommonString.getFormatInt(request.getParameter("status"));
			dbHelper.execute("update gift_product_advanced set status=? where uuid=?", new Object[]{ status, uuid }, connection);
			rs = "1";
		}
		//插入/更新套餐产品数据
		if(flag.equals("addPackageProduct")){
			String package_product_no = CommonString.getFormatPara(request.getParameter("package_product_no"));
			Map noMap = dbHelper.getMap("select (select product_no+',' from gift_product_package_product where package_product_no='" + package_product_no + "' for xml path('')) as productNoStr", connection);
			String productNoStr = "";
			String[] productNoAry = null;
			if(noMap != null){
				productNoStr = CommonString.getFormatPara(noMap.get("productNoStr"));
				productNoAry = productNoStr.split(",");
			}
			String productJsonStr = CommonString.getFormatPara(request.getParameter("product"));
			//删除数据库中有的，传入参数中没有的产品
			for(String pNo : productNoAry){
				if(!productJsonStr.contains(pNo)){
					dbHelper.execute("delete from gift_product_package_product where package_product_no='" + package_product_no + "' and product_no='" + pNo + "'", connection);
				}
			}
			
			//根据数据库中已有的产品，判断传入的产品是需要添加或者更新
			JSONArray productAry = new JSONArray(productJsonStr);
			if(productAry!=null && productAry.length()>0){
				for(int i=0; i<productAry.length(); i++){
					String product_no = CommonString.getFormatPara(productAry.getJSONObject(i).get("p"));
					int order_no = CommonString.getFormatInt(productAry.getJSONObject(i).get("o"));
					int is_main = CommonString.getFormatInt(productAry.getJSONObject(i).get("m"));
					if(productNoStr.contains(product_no)){
						dbHelper.execute("update gift_product_package_product set order_no=" + order_no + ",is_main=" + is_main + " where package_product_no='" + package_product_no + "' and product_no='" + product_no + "'", connection);
					}else{
						Object[] paras = { "admin", CommonDate.getToday("yyyy-MM-dd HH:mm:ss"), Common.getIp(request), UUID.randomUUID().toString(), package_product_no, product_no, order_no, is_main };
						dbHelper.execute("insert into gift_product_package_product values (?,?,?,?,?,?,?,?)", paras, connection);
					}
				}
			}
		}
		//生成商品短编号
		if(flag.equals("updateProductShortNo")){
			String no = CommonString.getFormatPara(request.getParameter("no"));
			String updateShortNo = "update gift_product set short_no=90000+id where no='" + no + "'";
			dbHelper.execute(updateShortNo, connection);
			rs = "1";
		}
		//生成商品短编号--gp 20150213
		if(flag.equals("updateProductShortId")){
			String id = CommonString.getFormatPara(request.getParameter("id"));
			String updateShortNo = "update gift_product set short_no=90000+id where id='" + id + "'";
			dbHelper.execute(updateShortNo, connection);
			rs = "1";
		}
		//更新订单商品的购买价
		if(flag.equals("updateBuyPrice")){
			String uuid = CommonString.getFormatPara(request.getParameter("uuid"));
			double buy_price = CommonString.getFormatDouble(request.getParameter("buy_price"));
			dbHelper.execute("update gift_order_product set buy_price=? where uuid=?",new Object[]{ buy_price, uuid }, connection);
			rs = "1";
		}
		//按条件导出订单
		if(flag.equals("exportOrder")){
			String order_status = CommonString.getFormatPara(request.getParameter("order_status"));
			String order_start_date = CommonString.getFormatPara(request.getParameter("order_start_date"));
			String order_end_date = CommonString.getFormatPara(request.getParameter("order_end_date"));
			String whereStr = "";
			String whereStr_p = "";
			if(!order_status.equals("")){
				whereStr += " and order_status=" + order_status;
				whereStr_p += " and order_status=" + order_status;
			}
			if(!order_start_date.equals("")){
				whereStr += " and add_date > '" + order_start_date + "'";
				whereStr_p += " and order_date > '" + order_start_date + "'";
			}
			if(!order_end_date.equals("")){
				whereStr += " and convert(varchar,add_date,23)<='" + order_end_date + "'";
				whereStr_p += " and convert(varchar,order_date,23)<='" + order_end_date + "'";
			}
			String orderQuery = "select order_num,add_date,mem_no,(case order_type when 0 then '普通订单' when 1 then '拍卖订单' when 2 then '团购订单' end) as order_type,product_total_price,ship_total_price,coupon_total_price,point_total_price from gift_order where 1=1" + whereStr;
			List<Map> orderList = dbHelper.getMapList(orderQuery, connection);
			
			String orderProductQuery = "select order_num,product_no,product_name,buy_price,buy_amount from view_gift_order_product where 1=1" + whereStr_p;
			List<Map> oPList = dbHelper.getMapList(orderProductQuery, connection);

			try {
				OutputStream os = response.getOutputStream();//将WritableWorkbook直接写入到输出流
				String fs = "太阳商城订单统计";
				fs = new String(fs.getBytes("gb2312"), "iso8859-1");
				response.reset();// 清空输出流
				response.setContentType("application/msexcel");// 定义输出类型
				response.setHeader("Content-disposition", "attachment; filename=" + fs + ".xls");// 设定输出文件头
				WritableWorkbook wwb = Workbook.createWorkbook(os);// 创建Excel工作表
				WritableSheet ws = wwb.createSheet("Sheet1", 0);

				int charTitle = 10;// 标题字体大小
				int charNormal = 10;// 标题字体大小
				// 用于标题
				WritableFont titleFont = new WritableFont(WritableFont.createFont("宋体"), charTitle, WritableFont.BOLD);
				WritableCellFormat titleFormat = new WritableCellFormat(titleFont);
				titleFormat.setBorder(Border.ALL, BorderLineStyle.THIN); // 线条
				titleFormat.setVerticalAlignment(VerticalAlignment.CENTRE); // 垂直对齐
				titleFormat.setAlignment(Alignment.CENTRE); // 水平对齐
				titleFormat.setWrap(false); // 是否换行
				titleFormat.setBackground(Colour.GRAY_25);// 背景色暗灰-25%

				// 用于带有formatting的Number对象
				WritableFont nf = new WritableFont(WritableFont.createFont("Times New Roman"), charNormal);
				// NumberFormat nf = new NumberFormat("#.##");
				WritableCellFormat wcfN = new WritableCellFormat(nf);
				wcfN.setBorder(Border.ALL, BorderLineStyle.THIN); // 线条
				wcfN.setVerticalAlignment(VerticalAlignment.CENTRE); // 垂直对齐
				wcfN.setAlignment(Alignment.CENTRE);// 水平对齐
				wcfN.setWrap(false); // 是否换行
				
				//标题行
				ws.setRowView(0,600);
				ws.setColumnView(0, 20); // 设置列宽,第1列
				ws.setColumnView(1, 20); // 设置列宽,第2列
				ws.setColumnView(2, 20); // 设置列宽,第3列
				ws.setColumnView(3, 15); // 设置列宽,第4列
				ws.setColumnView(4, 60); // 设置列宽,第5列
				ws.setColumnView(5, 15); // 设置列宽,第6列
				ws.setColumnView(6, 10); // 设置列宽,第7列
				ws.setColumnView(7, 20); // 设置列宽,第8列
				ws.setColumnView(8, 15); // 设置列宽,第9列

				Label tit00 =new Label(0,0,"订单号",titleFormat);
				ws.addCell(tit00);
				Label tit10 = new Label(1, 0, "下单时间", titleFormat);
				ws.addCell(tit10);
				Label tit20 = new Label(2, 0, "下单会员号", titleFormat);
				ws.addCell(tit20);
				Label tit30 = new Label(3,0,"订单类型",titleFormat);
				ws.addCell(tit30);
				Label tit40 = new Label(4, 0, "商品名称", titleFormat);
				ws.addCell(tit40);
				Label tit50 = new Label(5, 0, "单价", titleFormat);
				ws.addCell(tit50);
				Label tit60 = new Label(6, 0, "数量", titleFormat);
				ws.addCell(tit60);
				Label tit70 = new Label(7,0,"订单总金额",titleFormat);
				ws.addCell(tit70);
				Label tit80 = new Label(8,0,"运费金额",titleFormat);
				ws.addCell(tit80);

				int rows=1;
				for(int i=0; i<orderList.size(); i++){
					String order_num = CommonString.getFormatPara(orderList.get(i).get("order_num"));
					int current_order_product_count = 0; //当前订单中有几种商品
					for(int j=0; j<oPList.size(); j++){
						if(order_num.equals(CommonString.getFormatPara(oPList.get(j).get("order_num")))){
							current_order_product_count++;
							ws.setRowView(rows,500);
							Label lab0 = new Label(0, rows, order_num, wcfN);
						    ws.addCell(lab0);
							Label lab1 = new Label(1, rows, CommonDate.getFormatDate("yyyy-MM-dd HH:mm:ss", orderList.get(i).get("add_date")), wcfN);
						    ws.addCell(lab1);
						    Label lab2 = new Label(2, rows, CommonString.getFormatPara(orderList.get(i).get("mem_no")), wcfN);
						    ws.addCell(lab2);
						    Label lab3 = new Label(3, rows, CommonString.getFormatPara(orderList.get(i).get("order_type")), wcfN);
						    ws.addCell(lab3);
                            WritableHyperlink link4 = new WritableHyperlink ( 4, rows, new URL ( "http://www.52sdskj.com/product/" + CommonString.getFormatPara ( oPList.get ( j ).get ( "product_no" ) ) + ".htm" ) );
						    link4.setDescription(CommonString.getFormatPara(oPList.get(j).get("product_name")));
						    ws.addHyperlink(link4);
						    Label lab5 = new Label(5, rows, CommonString.getFormatPara(oPList.get(j).get("buy_price")), wcfN);
						    ws.addCell(lab5);
						    Label lab6 = new Label(6, rows, CommonString.getFormatPara(oPList.get(j).get("buy_amount")), wcfN);
						    ws.addCell(lab6);
						    Label lab7 = new Label(7, rows, Tools.getFormatDecimal(CommonString.getFormatDouble(orderList.get(i).get("product_total_price"))+CommonString.getFormatDouble(orderList.get(i).get("ship_total_price"))-CommonString.getFormatDouble(orderList.get(i).get("coupon_total_price"))-CommonString.getFormatDouble(orderList.get(i).get("point_total_price")), 1), wcfN);
						    ws.addCell(lab7);
						    Label lab8 = new Label(8, rows, CommonString.getFormatPara(orderList.get(i).get("ship_total_price")), wcfN);
						    ws.addCell(lab8);
							rows++;
						}
					}
					ws.mergeCells(0, rows-current_order_product_count, 0, rows-1);
					ws.mergeCells(1, rows-current_order_product_count, 1, rows-1);
					ws.mergeCells(2, rows-current_order_product_count, 2, rows-1);
					ws.mergeCells(3, rows-current_order_product_count, 3, rows-1);
					ws.mergeCells(7, rows-current_order_product_count, 7, rows-1);
					ws.mergeCells(8, rows-current_order_product_count, 8, rows-1);
				}
				
				// 写入Exel工作表
				wwb.write();
				// 关闭Excel工作薄对象
				wwb.close();
				os.close();
			} catch (Exception ex) {
				ex.printStackTrace();
			} finally {

			}
		}
		
		//发放商品卡
		if(flag.equals("issueCard")){
			String uuid = CommonString.getFormatPara(request.getParameter("uuid"));
			dbHelper.execute("update gift_card set is_issue=1 where uuid='" + uuid + "'", connection);
			rs = "1";
		}
		//取消发放商品卡
		if(flag.equals("cancelIssueCard")){
			String uuid = CommonString.getFormatPara(request.getParameter("uuid"));
			dbHelper.execute("update gift_card set is_issue=0,mem_no=null where uuid='" + uuid + "'", connection);
			rs = "1";
		}
		/************************商品网部分结束*************************/
		//如果是代理区域
		if("product_agent_area".equals(flag)){
			String agentId = CommonString.getFormatPara(request.getParameter("agentId"));
			String factoryId = CommonString.getFormatPara(request.getParameter("factoryId"));
			String sql = " select ca.area_id as id ,ca.area_name as name ,ca.parent_area_id as pId,checked = ( case when pafaa.agent_id is null then 'false' else 'true' end ) from comm_area ca left join pro_agent_factory_and_area pafaa on ca.area_id = pafaa.area_id and pafaa.agent_id = "+agentId+" and pafaa.factory_id = "+factoryId+" where ca.level_id < 3 order by ca.area_id asc ";
			List<Map> list = dbHelper.getMapList(sql,connection);
			JSONArray arrays = new JSONArray(list);
			rs = arrays.toString();
		}
		//城市
		if("choose_city".equals(flag)){
			String proId = CommonString.getFormatPara(request.getParameter("proId"));
			String sql = " SELECT area_id,area_name from used_area where parent_area_id ='"+proId+"' ";
			List<Map> list = dbHelper.getMapList(sql,connection);
			String cityStr = "<option value=''>选择城市</option>";
			for(Map m : list){
				cityStr += "<option value='"+m.get("area_id")+"'>"+m.get("area_name")+"</option>";	
			}
			rs = cityStr;
		}
		//生成二手 solr 索引
		if(flag.equals("generateAllUsedIndex")){
			String productQuery = "select eq.id,eq.img1_1,brand.name+eq.model+cat.name as title,eq.linkman_address,eq.linkman_phone,eq.price,eq.linkman_company  from used_equipment eq left join  used_brand brand on eq.brand_id = brand.id left join used_catalog cat on eq.category_id = cat.id";
			List<Map> productList = dbHelper.getMapList(productQuery, connection);
			if(productList!=null && productList.size()>0){
				String httpUrl = "http://192.168.50.98:5000/sun21_used";
				//String httpUrl = "http://192.168.50.98:5000/sun21_gift";
				HttpSolrServer server = new HttpSolrServer(httpUrl);
				server.deleteByQuery("*:*");
				SolrInputDocument doc = null;
				List<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();
				for(Map product : productList){
					System.out.println(CommonString.getFormatPara(product.get("id"))+"==") ;
					doc = new SolrInputDocument();
					doc.addField("id",CommonString.getFormatPara(product.get("id")));
					doc.addField("title",CommonString.getFormatPara(product.get("title")));
					doc.addField("link_address",CommonString.getFormatPara(product.get("link_address")));
					doc.addField("linkman_phone",CommonString.getFormatPara(product.get("linkman_phone")));
					doc.addField("linkman_company",CommonString.getFormatPara(product.get("linkman_company")));
					doc.addField("img1_1",CommonString.getFormatPara(product.get("img1_1")));
					doc.addField("price",CommonString.getFormatPara(product.get("price")));
					docs.add(doc);
				}
				server.add(docs);
				server.commit();
			}
			
			rs = "1";
		}
		//生成二手 solr 购买索引
		if(flag.equals("generateAllUsedBuyIndex")){
			String productQuery = "select id,title,detail,pub_date from used_buy where is_pub=1";
			List<Map> productList = dbHelper.getMapList(productQuery, connection);
			if(productList!=null && productList.size()>0){
				String httpUrl = "http://192.168.50.98:5000/sun21_used_buy";
				//String httpUrl = "http://192.168.50.98:5000/sun21_gift";
				HttpSolrServer server = new HttpSolrServer(httpUrl);
				server.deleteByQuery("*:*");
				SolrInputDocument doc = null;
				List<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();
				for(Map product : productList){
					System.out.println(CommonString.getFormatPara(product.get("id"))+"==") ;
					doc = new SolrInputDocument();
					doc.addField("id",CommonString.getFormatPara(product.get("id"))) ;
					doc.addField("title",CommonString.getFormatPara(product.get("title"))) ;
					doc.addField("detail",CommonString.getFormatPara(product.get("detail"))) ;
					doc.addField("pub_date",CommonString.getFormatPara(product.get("pub_date"))) ;
					docs.add(doc);
				}
				server.add(docs);
				server.commit();
			}
			rs = "1";
		}
		//生成二手 solr 资讯索引
		if(flag.equals("generateAllUsedNewsIndex")){
			String productQuery = "select id,title,content,pub_date,file_name from used_news where is_pub=1";
			List<Map> productList = dbHelper.getMapList(productQuery, connection);
			if(productList!=null && productList.size()>0){
				String httpUrl = "http://192.168.50.98:5000/sun21_used_news";
				//String httpUrl = "http://192.168.50.98:5000/sun21_gift";
				HttpSolrServer server = new HttpSolrServer(httpUrl);
				server.deleteByQuery("*:*");
				SolrInputDocument doc = null;
				List<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();
				for(Map product : productList){
					doc = new SolrInputDocument();
					doc.addField("id",CommonString.getFormatPara(product.get("id"))) ;
					doc.addField("title",CommonString.getFormatPara(product.get("title"))) ;
					doc.addField("content",CommonString.getFormatPara(product.get("content"))) ;
					doc.addField("pub_date",CommonString.getFormatPara(product.get("pub_date"))) ;
					doc.addField("file_name",CommonString.getFormatPara(product.get("file_name"))) ;
					docs.add(doc);
				}
				server.add(docs);
				server.commit();
			}
			rs = "1";
		}
		//生成二手 solr 图片
		if(flag.equals("generateAllUsedPicIndex")){
			String productQuery = "select eq.id, eq.img1_1,cast(eq.factorydate as varchar)+'产的'+ub.name+eq.model+uc.name title from used_equipment eq left join used_brand ub on eq.brand_id=ub.id left join used_catalog uc on eq.category_id=uc.id";
			List<Map> productList = dbHelper.getMapList(productQuery, connection);
			if(productList!=null && productList.size()>0){
				String httpUrl = "http://192.168.50.98:5000/sun21_used_pic";
				//String httpUrl = "http://192.168.50.98:5000/sun21_gift";
				HttpSolrServer server = new HttpSolrServer(httpUrl);
				server.deleteByQuery("*:*");
				SolrInputDocument doc = null;
				List<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();
				for(Map product : productList){
					doc = new SolrInputDocument();
					doc.addField("id",CommonString.getFormatPara(product.get("id"))) ;
					doc.addField("title",CommonString.getFormatPara(product.get("title"))) ;
					doc.addField("img1_1",CommonString.getFormatPara(product.get("img1_1"))) ;
					docs.add(doc);
				}
				server.add(docs);
				server.commit();
			}
			rs = "1";
		}
		/************************二手网部分开始*************************/
		//检测用户唯一
		if ("usedCheckUserUnique".equals(flag)) {
			String mem_no = CommonString.getFormatPara(request.getParameter("mem_no"));
			String query = "select id from used_member_ext where mem_no='" + mem_no + "'";
			Map userMap = dbHelper.getMap(query, connection);
			if (userMap == null) {
				rs = "ok"; //可以注册
			} else {
				rs = "no"; //不能注册
			}
		}
		/************************二手网部分结束*************************/
		
		// 批量审核通过
		if("reviewsCheck".equals(flag)){
			String ids = CommonString.getFormatPara(request.getParameter("del_id"));
			if (null != ids && ids.length() > 0) {
				String sql = "update used_equipment set is_review=1  where uuid in (" + ids+ ") ";
				rs = dbHelper.execute(sql,connection)+"";
			}
		}
		// 设备管理批量审核不通过
		if("reviewsNotCheck".equals(flag)){
			String ids = CommonString.getFormatPara(request.getParameter("del_id"));
			if (null != ids && ids.length() > 0) {
				String sql = "update used_equipment set is_review=-1  where uuid in (" + ids+ ") ";
				rs = dbHelper.execute(sql,connection)+"";
			}
		}
		
		// 供求供应信息批量审核不通过
		if("reviewsNotCheck2".equals(flag)){
			String ids = CommonString.getFormatPara(request.getParameter("del_id"));
			if (null != ids && ids.length() > 0) {
			String sql = "update sell_buy_market set is_review=-1,reviewContent='友情提示：您好，本网站只允许发布与工程机械行业相关的信息。客服热线：0535-6792736'  where uuid in (" + ids+ ") ";
				rs = dbHelper.execute(sql,connection)+"";
			}
		}
		// 供求供应推荐到首页
		if("rec".equals(flag)){
			String ids = CommonString.getFormatPara(request.getParameter("del_id"));
			String status = CommonString.getFormatPara(request.getParameter("status"));
			if (null != ids && ids.length() > 0) {
				String sql = "update sell_buy_market set rec_index_2 = 1  where uuid in (" + ids+ ") ";
				if(!status.equals("1")){
					sql = "update sell_buy_market set rec_index_2 = 0  where uuid in (" + ids+ ") ";
				}
				rs = dbHelper.execute(sql,connection)+"";
			}
		}
		// 更新日期
		if("updDate".equals(flag)){
			String ids = CommonString.getFormatPara(request.getParameter("del_id"));
			if (null != ids && ids.length() > 0) {
			String sql = "update sell_buy_market set pub_date=getdate(),orderno=replace(replace(replace(left(convert(varchar(30),getdate(),21),19),'-',''),':',''),' ','')  where uuid in (" + ids+ ") ";
				rs = dbHelper.execute(sql,connection)+"";
			}
		}
		
		// 批量显示
		if("showCheck".equals(flag)){
			String ids = CommonString.getFormatPara(request.getParameter("del_id"));
			if (null != ids && ids.length() > 0) {
				String sql = "update used_equipment set is_pub=1  where uuid in (" + ids+ ") ";
				rs = dbHelper.execute(sql,connection)+"";
			}
		}
		
		// 批量显示
		if("setRecommendMarket".equals(flag)){
			String ids = CommonString.getFormatPara(request.getParameter("del_id"));
			if (null != ids && ids.length() > 0) {
				String sql = "update member_info set is_recommendshop_market=1  where uuid in (" + ids+ ") ";
				rs = dbHelper.execute(sql,connection)+"";
			}
		}
		// 批量显示
		if("cancelRecommendMarket".equals(flag)){
			String ids = CommonString.getFormatPara(request.getParameter("del_id"));
			if (null != ids && ids.length() > 0) {
				String sql = "update member_info set is_recommendshop_market=0  where uuid in (" + ids+ ") ";
				rs = dbHelper.execute(sql,connection)+"";
			}
		}
		
		/*****************************新配件网部分开始*****************************/
		
		//生成全部配件的索引
		if(flag.equals("genAllPartIndex")){
			//rs = Common.doGet("http://part.21-sun.com/tools/solr/generate_all_part_index.jsp");
		}
		
		//删除配件索引
		if(flag.equals("delPartIndex")){
			String part_id = CommonString.getFormatPara(request.getParameter("part_id"));
			String dealer_id = CommonString.getFormatPara(request.getParameter("dealer_id"));
			//Common.doGet("http://part.21-sun.com/tools/solr/delete_part_index.jsp?part_id=" + part_id + "&dealer_id=" + dealer_id);
			rs = "1";
		}
		
		//生成全部供应商的索引
		if(flag.equals("genAllDealerIndex")){
			//rs = Common.doGet("http://part.21-sun.com/tools/solr/generate_all_dealer_index.jsp");
		}
		/*****************************新配件网部分结束*****************************/
		
		//复制产品--gp 2015/02/13
		if("copyProduct".equals(flag)){
			String id = CommonString.getFormatPara(request.getParameter("id"));
			if (null != id && !id.equals("")) {
				String	no = CommonDate.getToday("yyyyMMddHHmmss")+(int)(Math.random()*1000);
				String sql = " insert into gift_product (add_user ,add_ip ,channel_uuid,no,name ,category  ,brand,price ,price_promotion ,price_agent ,price_staff ,price_cost ,is_shuang11 ,price_shuang11 ,price_promotion_bak ,storage  ,storage_warning  ,img  ,intro,intro_product,intro_detail,intro_detail_text,intro_company,param,param_key,pub_date,view_count ,is_show  ,is_rec  ,order_no ,last_modify_user  ,last_modify_date,last_modify_ip  ,weight  ,is_free_ship ,is_cus ,cus_cycle_tip,min_buy_count ,index_rec_order_no,pro_brand,pro_product_id ,advanced_min_count ,is_package ,sell_amount ,is_rec_index ,spc_category,supplier ,param_key_no,m_intro ) select add_user ,add_ip ,channel_uuid,"+no+",name+'--复制' ,category  ,brand,price ,price_promotion ,price_agent ,price_staff ,price_cost ,is_shuang11 ,price_shuang11 ,price_promotion_bak ,storage  ,storage_warning  ,img  ,intro,intro_product,intro_detail,intro_detail_text,intro_company,param,param_key,pub_date,0 ,0  ,is_rec  ,order_no ,last_modify_user  ,last_modify_date,last_modify_ip  ,weight  ,is_free_ship ,is_cus ,cus_cycle_tip,min_buy_count ,index_rec_order_no,pro_brand,pro_product_id ,advanced_min_count ,is_package ,sell_amount ,is_rec_index ,spc_category,supplier ,param_key_no,m_intro  from gift_product where id = "+id+" ";
				int newProId = dbHelper.executeUpdate(sql,connection);
				rs = newProId+"";
			}
		}
		
		//更新合伙人提现--gp 2016/03/21
		if("getRefreshPayment".equals(flag)){
			List<Map> enumList = (List)application.getAttribute("enumList");
			List<Map> partnerValList = (List) CommonApplication.getEnumChildrenList("201",enumList);
			Map partnerValMap = new HashMap();
			if(partnerValList!=null){
				for(Map m : partnerValList){
					partnerValMap.put((String) m.get("no"), (String) m.get("val"));
				}
			}
			
			double mem_p_piont = 0.00;
			
			String allPartnerSql = "select * from gift_member where p_apply_flag=100";
			List<Map> allPartnerlist = dbHelper.getMapList(allPartnerSql,connection);
			if(allPartnerlist!=null){
				for(Map p : allPartnerlist){
					String partner_mem_no = CommonString.getFormatPara(p.get("mem_no"));
					String partner_p_flag = CommonString.getFormatPara(p.get("p_flag"));
					if(partnerValMap!=null){
						mem_p_piont = Double.parseDouble(partnerValMap.get(partner_p_flag).toString());
					}
					//佣金提点
					NumberFormat fmt = NumberFormat.getPercentInstance();  
			        fmt.setMaximumFractionDigits(0);//最多两位百分小数
			        String mem_p_piont_percent = fmt.format(mem_p_piont);
			        
			      	//我的会员
					//会员总购买金额
					double sumMember = 0.00;
					String sumMemberSql = "select sum(product_total_price) as sumTotal from gift_order o left join gift_member m on o.mem_no=m.mem_no where m.parent_memNo='"+partner_mem_no+"' and o.order_status=5 and o.is_partner_payment=1 and o.confirmrecive_date is not null ";
					Map sumMemberMap = dbHelper.getMap(sumMemberSql, connection);
					sumMember = CommonString.getFormatDouble(sumMemberMap.get("sumTotal"));
					//会员可提购买金额
					String sumMemberEnableSql = "select sum(product_total_price) as sumTotal,sum(total_crown_partner_payment) as sumCrownTotal,sum(total_diamond_partner_payment) as sumDiamondTotal,sum(total_gold_partner_payment) as sumGoldTotal from gift_order o left join gift_member m on o.mem_no=m.mem_no where m.parent_memNo='"+partner_mem_no+"' and o.order_status=5 and o.is_partner_payment=1 and o.confirmrecive_date is not null and DATEDIFF(day,o.confirmrecive_date,GETDATE())>7 and o.member_payoff_status=0 ";
					Map sumMemberEnableMap = dbHelper.getMap(sumMemberEnableSql, connection);
					double sumEnableMember = CommonString.getFormatDouble(sumMemberEnableMap.get("sumTotal"));
					//未入账
					double unenableSumMember = 0.00;
					String sumMemberUnenableSql = "select sum(product_total_price) as sumTotal from gift_order o left join gift_member m on o.mem_no=m.mem_no where m.parent_memNo='"+partner_mem_no+"' and o.order_status=5 and o.is_partner_payment=1 and o.confirmrecive_date is not null and DATEDIFF(day,o.confirmrecive_date,GETDATE())<=7 and o.member_payoff_status=0 ";
					Map sumMemberUnenableMap = dbHelper.getMap(sumMemberUnenableSql, connection);
					unenableSumMember = CommonString.getFormatDouble(sumMemberUnenableMap.get("sumTotal"));
					//会员可提现
					double enableMemberPyoff = 0.0;
					if(!partner_p_flag.equals("")||sumMemberEnableMap!=null){
						if(partner_p_flag.equals("201003")){//皇冠
							enableMemberPyoff = CommonString.getFormatDouble(sumMemberEnableMap.get("sumCrownTotal"));
						}else if(partner_p_flag.equals("201002")){//钻石
							enableMemberPyoff = CommonString.getFormatDouble(sumMemberEnableMap.get("sumDiamondTotal"));
						}else if(partner_p_flag.equals("201001")){//黄金
							enableMemberPyoff = CommonString.getFormatDouble(sumMemberEnableMap.get("sumGoldTotal"));
						}
					}
					
					//我的合伙人
					//合伙人总销售额
					double sumPartner = 0.00;
					String sumPartnerSql = "select sum(product_total_price) as sumTotal from gift_order o left join gift_member m on o.mem_no=m.mem_no where m.parent_memNo in (SELECT mem_no from gift_member where parent_memNo = '"+partner_mem_no+"') and o.order_status=5 and o.is_partner_payment=1 and o.confirmrecive_date is not null";
					Map sumPartnerMap = dbHelper.getMap(sumPartnerSql, connection);
					sumPartner = CommonString.getFormatDouble(sumPartnerMap.get("sumTotal"));
					//合伙人可提销售额
					double sumEnablePartner = 0.00;
					String sumEnablePartnerSql = "select sum(product_total_price) as sumTotal,sum(total_junior_member_payment) as sumJunToiortal from gift_order o left join gift_member m on o.mem_no=m.mem_no where m.parent_memNo in (SELECT mem_no from gift_member where parent_memNo = '"+partner_mem_no+"') and o.order_status=5 and o.is_partner_payment=1 and o.confirmrecive_date is not null and DATEDIFF(day,o.confirmrecive_date,GETDATE())>7 and o.partner_payoff_status=0 ";
					Map sumEnablePartnerMap = dbHelper.getMap(sumEnablePartnerSql, connection);
					sumEnablePartner = CommonString.getFormatDouble(sumEnablePartnerMap.get("sumTotal"));
					//未入账销售额
					double unenableSumPartner = 0.00;
					String sumUnenablePartnerSql = "select sum(product_total_price) as sumTotal from gift_order o left join gift_member m on o.mem_no=m.mem_no where m.parent_memNo in (SELECT mem_no from gift_member where parent_memNo = '"+partner_mem_no+"') and o.order_status=5 and o.is_partner_payment=1 and o.confirmrecive_date is not null and DATEDIFF(day,o.confirmrecive_date,GETDATE())<=7 and o.partner_payoff_status=0 ";
					Map sumUnenablePartnerMap = dbHelper.getMap(sumUnenablePartnerSql, connection);
					unenableSumPartner = CommonString.getFormatDouble(sumUnenablePartnerMap.get("sumTotal"));
					//合伙人可现
					double enablePartnerPayoff = 0.0;
					if(sumEnablePartnerMap!=null){
						enablePartnerPayoff = CommonString.getFormatDouble(sumEnablePartnerMap.get("sumJunToiortal"));
					}
					
					//已提现
					double alreadyPayoff = 0.00;
					String alreadyPayoffSql = "select sum(payoff) as sumTotal from gift_member_payoff where mem_no='"+partner_mem_no+"' and order_status = 100 ";
					Map alreadyPayoffMap = dbHelper.getMap(alreadyPayoffSql, connection);
					alreadyPayoff = CommonString.getFormatDouble(alreadyPayoffMap.get("sumTotal"));
					
					//提现中
					double isNowPayoff = 0.00;
					String isNowPayoffSql = "select sum(payoff) as sumTotal from gift_member_payoff where mem_no='"+partner_mem_no+"' and order_status = 1 ";
					Map isNowPayoffMap = dbHelper.getMap(isNowPayoffSql, connection);
					isNowPayoff = CommonString.getFormatDouble(isNowPayoffMap.get("sumTotal"));
			        
					if(sumMember!=0.0 || sumEnableMember!=0.0 || sumPartner!=0.0 ||sumEnablePartner!=0.0 || alreadyPayoff!=0.0 || isNowPayoff!=0.0){
						String totalSql = "update gift_member set member_total_sale="+sumMember+" , member_enable_sale="+sumEnableMember+",member_enable_payment="+enableMemberPyoff+",member_unenable_sale="+unenableSumMember+",partner_total_sale="+sumPartner+",partner_enable_sale="+sumEnablePartner+",partner_enable_payment="+enablePartnerPayoff+",partner_unenable_sale="+unenableSumPartner+",already_payoff="+alreadyPayoff+",isnow_payoff="+isNowPayoff+" where mem_no='"+partner_mem_no+"'";
						//System.out.println(totalSql);
						dbHelper.execute(totalSql, connection);
					}
				}
			}
		}
		
		
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		DBHelper.freeConnection(connection);
	}
	out.print(rs);
%>